<!-- 点餐导航 -->
<template>
	<view class="menu-nav-container">
		<ul class="menu-nav-list">
			<a :href="`#${item.menuName}`" :id="item.menuName" ref="navList" v-for="item in menuList" :key="item.menuId">
				<li class="menu-nav-list-item">{{ item.menuName }}</li>
			</a>
		</ul>
	</view>
</template>

<script>
	import { mapActions, mapState } from 'vuex'
	export default {
		created() {
			this.getMenuList()
		},
		computed: {
			...mapState(['menuList'])
		},
		mounted() {
			// 菜品列表菜品点击时，导航栏分类同步
			this.$bus.$on('menuNavClick', data => {
				this.$refs.navList.forEach(item => {
					item.id == data ? item.classList.add('menu-nav-active') : item.classList.remove('menu-nav-active')
				})
			})
		},
		methods: {
			...mapActions(['getMenuList'])
		}
	}
</script>

<style scoped lang="scss">
	.menu-nav-container {
		width: 30vw;
		height: 100vh;
		overflow: auto;
		border-radius: 1vh;
		position: sticky;
		top: 0;
		margin-left: 10px;
		.menu-nav-list {
			height: 100vh;
			text-align: center;
			font-size: 14px;
			display: flex;
			flex-direction: column;
			background-color: #efefef;
			.menu-nav-list-item {
				background-color: #efefef;
				padding: 6px;
				flex: 10vh 1 0;
				line-height: 10vh;
				&:hover {
					background-color: #efe;
				}
			}
			a {
				color: black;
				&:visited {
					color: black;
				}
			}
		}
	}
</style>